<template>


    <a-modal :title="title" :width="900" :destroyOnClose="true" :maskClosable="false"
             :visible="visible" @cancel="handleCancel"
    >


        <StaffSelector   :valueList="staffList" @callBack="(e)=>{this.staffList=e}"/>

        <!-- Modal 页脚 -->
        <template slot="footer">
            <a-button @click="handleCancel">关闭</a-button>
            <a-button type="primary" :loading="loading" @click="onSubmit">保存</a-button>
        </template>

    </a-modal>

</template>
<script>

    import {authorizestaffList,saveAuthorizeStaffList} from '../public/http.js';

    export default {

        props: ["taskObj"],

        components: {
            StaffSelector: resolve => {require(['../../hrms/component/StaffSelector'], resolve);},
        },

        data() {
            return {

                loading: false, //按钮Loading
                title: "授权人员设置",
                staffList: [],
                visible: true, //modal 显示状态
            };
        },
        methods: {


            //根据授权ID保存授权人员列表
            onSubmit(){
                let taskId=this.taskObj.id;
                //返回数组中的代码列组成新数组
                let dataArr=  this.staffList.map(item => item.staffCode);
                //后台需要 把数组转成字符串  变成一个JSON 给后台处理
                let obj={dataArr:dataArr.toString()};
                saveAuthorizeStaffList(taskId,obj ).then(res=>{
                    if(res.code===0){
                        this.$notification.success({
                            message: '操作成功',
                            description: res.message
                        });

                        //关闭弹窗
                        this.visible = false;
                        this.$emit('closeModal', {render: false});
                    }else{
                        this.$notification.error({
                            message: '操作失败',
                            description: res.message
                        });

                    }





                })

            },

            //关闭弹窗
            handleCancel() {
                this.visible = false;
                this.$emit('closeModal', {
                    render: false
                });
            },



            ///分组选择
            onChange(checkedValues) {
                console.log('checked = ', checkedValues);
            },


            //1.0 根据授权计划获取人员列表

            getAuthorizeStaffList() {
                //根据授权ID获取人员列表
                authorizestaffList(this.taskObj.id).then(res => {
                    if (res.code === 0) {
                        this.staffList = res.data.result;
                    }


                })

            },

        },
        created() {
            this.getAuthorizeStaffList();
        }
    };
</script>